<template>
	<!-- <van-nav-bar  :title="title"
	:left-text="leftText"
	:right-text="rightText"
	:left-arrow='goBackIcon'
	@click-left="_onClickLeft"
	@click-right="_onClickRight"
	/> -->

<van-nav-bar ref='tabNav' :title="$H(this,'_title')" :fixed=true
	:left-text="$H(this,'leftText')"
	v-if="!$route.meta.hideHeader"
	:right-text="$store.state.user.tabNavText.rightText"
	:left-arrow='$route.matched.length>1&&!$route.meta.hideBackIcon'
	@click-left="_onClickLeft"
	@click-right="_onClickRight">
	<template #right>
      <van-icon   v-if='rightIcon' :name="rightIcon"/> 
	</template>
	<!-- {{$route.meta.rightText}} -->
	</van-nav-bar>

</template>
<script>
	import { getToken } from '@/utils/auth'
	export default{
		name: 'common-header',
		props:{
			onClickLeft:{
				type:Function,
				default(e){
					//console.log('3',e,this)
					this.$router.go(-1)
			
				}
			},
			onClickRight:{
				type:Function,
				default:()=>{
				//console.log('211')
				}
			}
		},
		data(){
			return{
				title:'',
				
				rightIcon:false,
				leftText:'',
				rightText:this.$route.meta.rightText,
				goBackIcon:'',
			}
		},
		watch:{
			'$route' (to, from , next ) {
				console.log('- --',from,this.$store.getters)
				let tabNavText = this.$store.getters.tabNavText
				tabNavText.rightText = this.$H(this,'rightText')
				this.$store.dispatch('user/updateTabInfo', tabNavText) 
					//this.rightText=to.meta.rightText
					//this.leftText=to.meta.leftText
				// data数据操作
				if(getToken()) {
					if(from.name==='Login'){
						//this.$router.replace(to)
					}else{
						//this.$router.replace(to)
					}
				}else{
					//this.$router.replace({name:'Login'})
				}
			}
		},
		methods:{
			_onClickLeft(e){
				
		
				if(this.$route.meta.onClickLeft && typeof(this.$route.meta.onClickLeft)==='function'){
					//this.$emit('onClickLeft',e)
					this.$route.meta.onClickLeft(e,this)
				}else{
			
					this.back()
				}
			},
			_onClickRight(e){
				console.log('rightIocn',e,this)
				
				
					if(this.$route.meta.onClickRight && typeof(this.$route.meta.onClickRight)==='function'){
						//this.$emit('onClickRight',e)
						//this.$route.meta.title='2'
						this.$route.meta.onClickRight(e,this)
					}	
			}
			
		}
	}
</script>
<style lang="less" scoped>
	
</style>